package com.example.common.config;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

/**
 * @Author Peng Yisheng
 * @Date 2024/11/19 0:25
 * @Description 服务定义类：无论下游是什么样的服务都需要进行注册
 */
@Builder
@Getter
@Setter
public class ServiceDefinition implements Serializable {
    private static final long serialVersionUID = -8263365765897285189L;

    private String uniqueId;  // 唯一的服务ID: serviceId:version

    private String serviceId; // 服务唯一id

    private String version;  // 服务的版本号

    private String protocol;  // 服务的具体协议：http(mvc http) dubbo ..

    private String patternPath;  // 路径匹配规则：访问真实ANT表达式：定义具体的服务路径的匹配规则

    private String envType;  // 环境名称

    private boolean enable = true;  // 服务启用禁用

    private Map<String, ServiceInvoker> invokerMap;  // 服务列表信息


    public ServiceDefinition() {
        super();
    }

    public ServiceDefinition(String uniqueId, String serviceId, String version, String protocol, String patternPath,
                             String envType, boolean enable, Map<String, ServiceInvoker> invokerMap) {
        super();
        this.uniqueId = uniqueId;
        this.serviceId = serviceId;
        this.version = version;
        this.protocol = protocol;
        this.patternPath = patternPath;
        this.envType = envType;
        this.enable = enable;
        this.invokerMap = invokerMap;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (this == null || getClass() != o.getClass()) return false;
        ServiceDefinition serviceDefinition = (ServiceDefinition) o;
        return Objects.equals(uniqueId, serviceDefinition.uniqueId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(uniqueId);
    }

}
